home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-68k-src / machines / amiga68k / libsrc / stdlib / getenv.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  553b  |  24 lines

  1. #include <stdlib.h>
  2. #include <dos/dos.h>
  3. #include <dos/var.h>
  4. #include <proto/dos.h>
  5.  
  6. char *getenv(const char *name)
  7. { static char *var=NULL;
  8.   size_t len,i=0;
  9.   do
  10.   { i+=256;
  11.     if(var!=NULL) /* free old buffer */
  12.       free(var);
  13.     var=malloc(i); /* and get a new one */
  14.     if(var==NULL) /* Oh, dear */
  15.       return NULL;
  16.     len=GetVar((STRPTR)name,var,i,GVF_BINARY_VAR)+1;
  17.   }while(len>=i); /* just to be sure we got everything, we _require_ 1 unused byte */
  18.   if(len==0) /* Variable doesn't exist */
  19.     return NULL;
  20.   else
  21.     return var;
  22. }
  23.  
  24.